package com.pi.controller;

import com.pi.dao.ReceiveDao;
import com.pi.po.ReportPO;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

public class ReceiveController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        resp.setHeader("pageEncoding","UTF-8");
        int num=Integer.parseInt(req.getParameter("report_column_number"));
        ReportPO report=new ReportPO();
        try {
            report=new ReceiveDao().getReport(req.getParameter("user_id"),req.getParameter("user_report_id"));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        String[] ts=new String[]{
                report.getT1(),report.getT2(),report.getT3(),report.getT4(),
                report.getT5(),report.getT6(),report.getT6(),report.getT7(),
                report.getT8(),report.getT9(),report.getT9(),report.getT10(),
                report.getT11(),report.getT12()
        };
        String res="<html><head><title>填写表格</title></head><form action='http://47.100.105.127:8080/pi/receiveData' method='POST'>" +
                "<input type='text' name='user_id' hidden=\"hidden\" value='"+report.getUserId()+"'/>" +
                "<input type='text' name='user_report_id' hidden=\"hidden\" value='"+report.getUserReportId()+"'/>" +
                "<input type='text' name='report_column_number' hidden=\"hidden\" value='"+report.getReportColumnNumber()+"'/>" +
                "<table><tr>";
        for(int i=0;i<num;i++){
            res+="<th>"+ts[i]+"</th>";
        }
        res+="</tr><tr>";
        for(int i=0;i<num;i++){
            res+="<td><input type='text' name='t"+(i+1)+"'/></td>";
        }
        res+="</tr></table><br/><input type='submit' value='提交'/></form></html>";

        PrintWriter writer=resp.getWriter();
        writer.println(res);
        writer.close();
    }
}
